function [] = ZP_rain(indir0,outdir0,period_list)
% ZP_rain.m 9/7/2011 Parker MacCready
%
% adds rain_con and rain_non, and take the time derivative
% so we get precipitation RATE

disp('--- ZP_rain ---')

g_list = {'d2';'d3'};

for pp = 1:length(period_list)
    period = period_list{pp};
    disp(['period = ',period])
    for gg = 1:length(g_list)
        g_tag = g_list{gg};
        indir = [indir0,period,'/'];
        outdir = [outdir0,period,'/'];
        
        load([indir,'rainc_',g_tag,'.mat']);
        % now this is actually the accumulation since the start of the
        % forecast, so we can estimate the precipitation RATE by
        % dividing by the time since the start of the forecast.  This is
        % easy to do since we kept that information in the ts2 cell array!
        [NT,NR,NC] = size(outmat);
        for tt = 1:NT
            ts2 = ts2_vec{tt};
            dt_sec = 3600 * str2num(ts2(3:4));
            % the 0.1 gets us from mm to cm
            outmat(tt,:,:) = 0.1 * outmat(tt,:,:) / dt_sec;
        end
        % units of rain are now cm s-1
        
        save([outdir,'rain','_',g_tag,'.mat'],'lon','lat','tdvec', ...
            'ts1_vec','ts2_vec','outmat','-v7.3');
        
    end % end of gg loop
    
end
